#pragma once
#include "Sock.h"
#include "snetwork/CDynamicClass.h"
#include "standard/DBConfig.h"
#include "standard/MyPool.h"

typedef struct { 
    void                *data;
    void                *read;//nl_event_t
    void                *write;// nl_event_t
    int                 fd;

//    http_recv_pt         recv;
//    http_send_pt         send;
    off_t               sent;
    nlu_pool_t         *pool;
    struct sockaddr    *sockaddr;
    int                 socklen;
    char    *           addr_text;

    struct sockaddr     *local_sockaddr;

    char                *buffer;
    unsigned            buffered:8;
    unsigned            log_error:3;     /* ngx_connection_log_error_e */
    unsigned            single_connection:1;
    unsigned            unexpected_eof:1;
    unsigned            timedout:1;
    unsigned            error:1;
    unsigned            destroyed:1;

    unsigned            idle:1;
    unsigned            reusable:1;
    unsigned            close:1;

    unsigned            sendfile:1;
    unsigned            sndlowat:1;
    unsigned            tcp_nodelay:2;   /* ngx_connection_tcp_nodelay_e */
    unsigned            tcp_nopush:2;    /* ngx_connection_tcp_nopush_e */

} nl_connection_t;


namespace Sock
{   
    class  SNETWORK_API CNluConnection
    {
    public:
        static CNluConnection *instance();
        CNluConnection();
        int execute(void* pa);
        nlu_connection_t *getConnection(nlu_cycle_t *cycle, int s);
        void freeConnection(nlu_cycle_t *cycle, nlu_connection_t *c);

	protected:
		DBConfig *m_dbconfig;
		//paramArr *m_par;
		
    private: 
        static CNluConnection* m_instance;    
        class CGarbo {public: ~CGarbo(){if (CNluConnection::m_instance) delete CNluConnection::m_instance;}};
        static CGarbo Garbo;
    };
}
